package com.xjy.web.controller.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.xjy.common.annotation.RepeatSubmit;
import com.xjy.common.annotation.Log;
import com.xjy.common.core.controller.BaseController;
import com.xjy.common.core.domain.AjaxResult;
import com.xjy.common.enums.BusinessType;
import com.xjy.system.domain.vo.ReportMaterialDetailVo;
import com.xjy.system.domain.bo.ReportMaterialDetailQueryBo;
import com.xjy.system.domain.bo.ReportMaterialDetailAddBo;
import com.xjy.system.domain.bo.ReportMaterialDetailEditBo;
import com.xjy.system.service.IReportMaterialDetailService;
import com.xjy.common.utils.poi.ExcelUtil;
import com.xjy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * VIEWController
 *
 * @author xjy
 * @date 2022-03-27
 */
@Api(value = "VIEW控制器", tags = {"VIEW管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/report_material_detail")
public class ReportMaterialDetailController extends BaseController {

    private final IReportMaterialDetailService iReportMaterialDetailService;

    /**
     * 查询VIEW列表
     */
    @ApiOperation("查询VIEW列表")
    @PreAuthorize("@ss.hasPermi('system:materialDetail:list')")
    @GetMapping("/list")
    public TableDataInfo<ReportMaterialDetailVo> list(@Validated ReportMaterialDetailQueryBo bo) {
        return iReportMaterialDetailService.queryPageList(bo);
    }

    /**
     * 导出VIEW列表
     */
    @ApiOperation("导出VIEW列表")
    @PreAuthorize("@ss.hasPermi('system:materialDetail:export')")
    @Log(title = "VIEW", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ReportMaterialDetailVo> export(@Validated ReportMaterialDetailQueryBo bo) {
        List<ReportMaterialDetailVo> list = iReportMaterialDetailService.queryList(bo);
        ExcelUtil<ReportMaterialDetailVo> util = new ExcelUtil<ReportMaterialDetailVo>(ReportMaterialDetailVo.class);
        return util.exportExcel(list, "VIEW");
    }

    /**
     * 获取VIEW详细信息
     */
    @ApiOperation("获取VIEW详细信息")
    @PreAuthorize("@ss.hasPermi('system:materialDetail:query')")
    @GetMapping("/{projId}")
    public AjaxResult<ReportMaterialDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("projId") Long projId) {
        return AjaxResult.success(iReportMaterialDetailService.queryById(projId));
    }

    /**
     * 新增VIEW
     */
    @ApiOperation("新增VIEW")
    @PreAuthorize("@ss.hasPermi('system:materialDetail:add')")
    @Log(title = "VIEW", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ReportMaterialDetailAddBo bo) {
        return toAjax(iReportMaterialDetailService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改VIEW
     */
    @ApiOperation("修改VIEW")
    @PreAuthorize("@ss.hasPermi('system:materialDetail:edit')")
    @Log(title = "VIEW", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ReportMaterialDetailEditBo bo) {
        return toAjax(iReportMaterialDetailService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除VIEW
     */
    @ApiOperation("删除VIEW")
    @PreAuthorize("@ss.hasPermi('system:materialDetail:remove')")
    @Log(title = "VIEW" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{projIds}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] projIds) {
        return toAjax(iReportMaterialDetailService.deleteWithValidByIds(Arrays.asList(projIds), true) ? 1 : 0);
    }
}
